package com.groupbuying.settleproducer.controller;

import com.groupbuying.settleproducer.connector.YSFeign;
import com.groupbuying.settleproducer.constants.SettleWithdrawalSearchConstants;
import com.groupbuying.settleproducer.dto.YSBalanceAccountDetailDTO;
import com.groupbuying.settleproducer.dto.YSBalanceReturnDTO;
import com.groupbuying.settleproducer.utils.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author WANGNING
 * @email wyn20140226@aliyun.com
 * @date 2019-05-26 01:53:15
 * @des 一清提现银盛余额查询
 */
 
@RestController
@RequestMapping("/settleproduce/settleBalance")
public class SettleUshopYSBalanceController {
	@Autowired
	private YSFeign ysFeign;

	/**
	 * 查找银盛余额feign
	 */
	@PostMapping("/query")
	public R queryBalance(@RequestParam Map<String, Object> params){
		System.out.println("======= 开始请求银盛一清提现余额查询参数！！=========");
		Map<String,Object> condMap=new HashMap<>();
		String json=JsonUtils.stringToJsonByFastjson(SettleWithdrawalSearchConstants.MERCHANT_USERCODE, (String)params.get("merchant_usercode"));
		condMap.put("biz_content", json);
		String balanceJson=ysFeign.balanceQuery(condMap);
		YSBalanceReturnDTO ysBalanceReturnDTO= (YSBalanceReturnDTO) JsonUtils.convertBean(balanceJson, YSBalanceReturnDTO.class);
		List<YSBalanceAccountDetailDTO> balanceAccountDetailList= ysBalanceReturnDTO.getAccount_detail();
		String accountAmount=balanceAccountDetailList.get(0).getAccount_amount();
		if(accountAmount!=null){
			return R.ok(accountAmount);
		}
		return R.error();
	}

}
